package com.hundsun.cprs.yyt.service.mq;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.hundsun.cprs.yyt.service.match.service.TradeMatchInnerService;
import com.hundsun.cprs.yyt.service.system.domain.BussinessParam;
import com.hundsun.cprs.yyt.service.system.enums.EnumBussinessParam;

@Component
public class SytemParamChangeListener implements MessageListener {
    private static Log logger = LogFactory.getLog(SytemParamChangeListener.class);
    @Autowired
    private TradeMatchInnerService tradeMatchService;
    
    @Override
    public void onMessage(Message message) {
        try {
            BussinessParam param = JSON.parseObject(new String(message.getBody()), BussinessParam.class);
            if (logger.isDebugEnabled()) {
                logger.debug("系统参数变更通知:" + JSON.toJSONString(param));
            }
            
            if (StringUtils.equalsIgnoreCase(param.getBussinessKey(), EnumBussinessParam.MATCH_NEW_WEIGHT.getCode())) {
                //权重值变更
                tradeMatchService.resetMatchingSellQueueWeight(param.getBussinessValue());
            }
            
            if (StringUtils.equalsIgnoreCase(param.getBussinessKey(), EnumBussinessParam.MATCH_BUY_NEWUSER_RATE.getCode())) {
                //权重值变更
                tradeMatchService.resetMatchBuyNewUserRate(param.getBussinessValue());
            }
        } catch (Exception e) {
            logger.error("系统参数变更通知处理异常",e);
        }
    }

}
